home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / doc / EXTENSIONS.DOC < prev    next >
Text File  |  1994-02-13  |  16KB  |  416 lines

  1.  
  2. extensions/extensions                    extensions/extensions
  3. extensions/EXTENSIONS                    extensions/EXTENSIONS
  4.  
  5.                    COMPILER EXTENSIONS
  6.  
  7.                  AUTO LIBRARY OPENNING
  8.  
  9.     Most Amiga libraries are supported on an autoinit basis.  Normally you
  10.     declare the library base variable then OpenLibrary() it in your main.
  11.  
  12.     If you EXTERN the library base variable instead or simply not declare
  13.     it at all then it will be brought in from auto*.lib along with autoinit
  14.     code to automatically OpenLibrary() it on startup and CloseLibrary() it
  15.     on shutdown.
  16.  
  17.     DICE uses this feature to automatically open floating point libraries,
  18.     dos.library, etc...  For example, with DICE you can write a program
  19.     which simply calls intuition's OpenWindow() function without having
  20.     to OpenLibrary/CloseLibrary "intuition.library".
  21.  
  22.     Others will be added in the future, eventually all the libraries.
  23.  
  24.     Note that the auto-open features is fully upward compatible to earlier
  25.     methods of declaring the base pointer and openning the libraries
  26.     manually.  Declaring a library base variable causes the associated
  27.     autolib routines to NOT be linked into the executable.
  28.  
  29.            TYPE QUALIFIER AND STORAGER QUALIFIER EXTENSIONS
  30.  
  31.     availability:   reg-only = registered users
  32.  
  33.  
  34.     extension    avail        comment
  35.  
  36.     volatile    all        force auto's to NOT be placed in registers
  37.     const    all        place data items in the code section (see -ms/-mS)
  38.     __autoinit    all        cause a subroutine to be run automatically
  39.                 before _main (for variables, puts variable in
  40.                 alternate section)
  41.     __autoexit    all        cause a subroutine to be run automatically
  42.                 before _exit
  43.     __interrupt all        NOT AMIGA COMPATIBLE
  44.     __chip    reg-only    cause storage to be placed in CHIP memory
  45.     __far    all        cause storage to be referenced using absolute-long
  46.     __near    all        cause storage to be referenced using A4-relative
  47.     __aligned    all        cause storage to be aligned on a longword boundry
  48.     __unaligned all        allows structures to be byte-aligned (at your own risk)
  49.     __geta4    reg-only    cause a subroutine to setup the A4 data base
  50.                 pointer
  51.  
  52.     __shared    all        storage is placed in the code section and thus
  53.                 is shared between instances of a resident'd
  54.                 program.  EXPERIMENTAL
  55.  
  56.     __regargs    all        specify function takes registered arguments
  57.                 even if -mr/-mR/-mRR is not used.
  58.  
  59.     __stkargs    all        specify function takes normal stack based
  60.                 args despite the possibility that -mr/-mR/-mRR
  61.                 has been specified.
  62.  
  63.     __dynamic    reg-only    dynamic linking of routines/variables at run-
  64.                 time
  65.  
  66.     __noprof    all        disable profiling for a procedure
  67.  
  68.     __D0-__D7    reg-only    explicit register specification for procedure
  69.     __A0-__A7            arguments.
  70.  
  71.     volatile
  72.     This storage qualifier normally specifies that the physical storage
  73.     is 'synched' at the end of each line of C code.  DICE already does
  74.     this by virtue of not doing any major optimizations.  Under ANSI
  75.     this storage qualifier also forces auto variables to NOT be placed
  76.     in a register.    This can be important if you use <setjmp.h>
  77.     (see MAN/SETJMP.DOC for more information)
  78.  
  79.     const
  80.     The const type qualifier can be handled in different ways by DICE.
  81.     As of the 2.05.11 version of DC1, any const qualified object is
  82.     placed in the code section.  Before 2.05.11 const qualified
  83.     objects were only placed in the code section if -ms or -mS was
  84.     also given to DCC.
  85.  
  86.     Normally a const qualified item is handled as a near item (pc-rel)
  87.     within the module that declares it, and handled with absolute-long
  88.     references in modules that extern it.
  89.  
  90.     If -ms is used then string constants are made const.  If -mS is
  91.     used then all external references to const items use pc-relative
  92.     instead of the absolute-long addressing mode.  Do NOT use -mS
  93.     unless your final code size is less than 32KBytes.
  94.  
  95.     Using -ms can substantially reduce the number of run-time
  96.     relocations for -r residentable programs as well as the run-time
  97.     dynamically allocated data+bss space.
  98.  
  99.     (refer to DCC.DOC, -ms and -mS options for details)
  100.  
  101.     __autoinit
  102.     __autoexit
  103.  
  104.     These storage qualifiers cause a routine to be called after libraries
  105.     are openned before _main is called (__autoinit), and just before
  106.     libraries are closed after _exit is called (__autoexit).  They may
  107.     be used for low level initialization and shutdown and may not make
  108.     any c.lib calls (i.e. malloc, fopen, open, etc... may not be called)
  109.  
  110.     __autoinit void
  111.     fubar()
  112.     {
  113.         NewList(&MyList);
  114.     }
  115.  
  116.     __autoinit may be used with a variable declaration.  The variable
  117.     is placed in an alternate section.  This is mainly of use for
  118.     ROMable applications to group declared data together, with a base
  119.     section pointer in the ROM startup object and a 'terminator'
  120.     in the last object module.  For example, a 'ROM MODULE LIST' may
  121.     be constructed painlessly using this feature.
  122.  
  123.     __autoinit int a;        /*    altbss,bss    */
  124.     __autoinit int a = 4;        /*    altdata,data    */
  125.     __autoinit const int a;     /*    altcode,code    */
  126.     __autoinit const int a = 4; /*    altcode,code    */
  127.  
  128.     SUGGESTION:  use dcc -a to oberve the assembly generated.  Note
  129.     that BSS data verses INITIALIZED data go into different sections.
  130.  
  131.     __interrupt
  132.  
  133.     This storage qualifier for a subroutine causes all used registers to
  134.     be saved and restored, including the scratch registers, and returns
  135.     via RTE instead of RTS.
  136.  
  137.     THIS KEYWORD IS NOT AMIGA COMPATIBLE
  138.  
  139.     __noprof
  140.  
  141.     When a source module is compiled with -prof each routine is
  142.     generally profiled.  The __noprof qualifier for a procedure
  143.     declaration disables profiling for the routine in question.
  144.     This is used, specifically, to prevent the profiling routine
  145.     from profiling itself (result = crash) in the support library.
  146.  
  147.     __chip
  148.  
  149.     This storage qualifier forces a static or global data item to be
  150.     placed in CHIP memory.    Normally this precludes being able to make
  151.     such programs resident (-r option), but if you also use the 'const'
  152.     type qualifier you can make such programs resident....    The 'const'
  153.     type qualifier assumes that the contents of the object will NEVER
  154.     be modified!!!
  155.  
  156.     __chip short ImageData[] = { ... };        read-write object
  157.                             program not residentable
  158.  
  159.     __chip const short ImageData[] = { ... };   read-only object
  160.                             program is residentable
  161.  
  162.     __far
  163.  
  164.     __far int a;
  165.  
  166.     This storage qualifier determines how a data object is to be
  167.     referenced.  It overides the data model for the reference and
  168.     forces the ABSOLUTE-LONG addressing mode to be used.
  169.  
  170.     Note that __chip data is automatically forced to be __far.
  171.     When compiling -mD the default is to use __far references.
  172.  
  173.     WARNING:  Using __far addressing on non-const data items precludes
  174.     the executable from being residentable.
  175.  
  176.     __near
  177.  
  178.     __near int a;
  179.  
  180.     This storage qualifier forces a small-data model (A4-Relative)
  181.     reference to a data object.  When using the -md (default) data
  182.     model data objects are accessed as near items by default.
  183.  
  184.     __aligned
  185.  
  186.     This storage qualifier forces the static, global, or auto data
  187.     object to be aligned on a longword boundry.
  188.  
  189.     foo()
  190.     {
  191.         __aligned struct FileInfoBlock fib;
  192.         ...
  193.     }
  194.  
  195.     WARNING:    __aligned does not work if this subroutine or any
  196.     higher level subroutine is passed a *structure* where said
  197.     structure is not aligned.  We are talking about passing actual
  198.     structures here, not pointers to structures (which work fine
  199.     with __aligned).  Note that passing char or short integers works
  200.     just fine with __aligned.
  201.  
  202.     __unaligned
  203.  
  204.     This storage qualifier allows structures to be byte-aligned in
  205.     terms of NOT padding them to the nearest word or longword.
  206.  
  207.         __unaligned struct foo {
  208.         char a;
  209.         } a, b, c;
  210.  
  211.     In the above example, sizeof(a), sizeof(b), and sizeof(c) is 1.
  212.  
  213.     USE AT YOUR OWN RISK.  Accessing word/long/ptr items at odd
  214.     byte addresses is illegal for the 68000 and will generate an
  215.     exception.  This qualifier is useful mainly for character
  216.     structures that must map over a text file.
  217.  
  218.     __geta4
  219.  
  220.     This storage qualifier on a subroutine definition forces the
  221.     subroutine to save A4 and then load A4 with the small-data model
  222.     data pointer on subroutine entry, then restore the original
  223.     contents of A4 on subroutine exit.  This is useful for
  224.     inter-context calls when using the small-data model.
  225.  
  226.     __geta4 void
  227.     fubar()
  228.     {
  229.  
  230.     }
  231.  
  232.     Unfortunately, using this qualifier precludes being able to
  233.     generate a residentable executable since a residentable
  234.     executable's data space pointer is unknown at link time.
  235.  
  236.     __shared
  237.  
  238.     This storage modifier places the global or static variable
  239.     declaration into the code segment, thus this variable will be
  240.     SHARED across multiple running instances of the same program,
  241.     assuming the program has been made RESIDENT.  A program that has
  242.     not been made resident will not share variables.
  243.  
  244.     __config    (UNDER TESTING, DO NOT USE FOR ANY REAL PROJECT)
  245.  
  246.     This storage modifier generates loading and saving code for all
  247.     variables in question.    You should not declare any pointers as
  248.     a saved pointer value will not be valid when the program is run
  249.     later on.
  250.  
  251.     If no configuration file exists the initialized value of the static
  252.     or global storage is used, for example:
  253.  
  254.         __config int a = 34;
  255.  
  256.     'a' will be 34 if no configuration file exists.  If a configuration
  257.     file does exist all __config variables will be overriden with the
  258.     values stored in the configuration file.
  259.  
  260.     The name and version of the configuration file must be specified
  261.     by the programmer as two initialized global variables or a link
  262.     error will occur.  For example:
  263.  
  264.         char *ConfigFile = "s:myprog.config";
  265.         long ConfigVersion = 1;
  266.  
  267.     DICE configuration code will automatically ignore any configuration
  268.     file whos version does not equal ConfigVersion.  As a programmer,
  269.     you must change ConfigVersion if you modify ANY __config
  270.     declaration, the ordering of any __config declaration, or the
  271.     ordering of any object modules in your link.  If you fail to do so,
  272.     the program may attempt to load an invalid configuration.
  273.  
  274.     The configuration is automatically loaded on program startup,
  275.     before _main() (__main from assembly) gets run, and if ConfigFile
  276.     is non-NULL on program exit (_exit) then the configuration will be
  277.     saved.     Thus, __config is supported even if you use the _main()
  278.     entry point and _exit() exit point.
  279.  
  280.     WARNING: ONLY PROCESSES MAY USE THE __CONFIG TYPE QUALIFIER.  If
  281.     you plan to run a program as a task instead of a process then you
  282.     cannot use __config.  Note that any WORKBENCH or CLI run program
  283.     is a process.  DOS handlers are also processes, but it is not
  284.     suggested that __config be used for any program that is to be
  285.     a DOS handler (i.e. a DOS device).  Libraries and exec Devices are
  286.     NOT processes... not even tasks usually, and thus __config may not
  287.     be used for such programs.
  288.  
  289.     __regargs
  290.     __stkargs
  291.  
  292.     Normally these qualifiers are used in conjuction with the -mr,
  293.     -mR, or -mRR flags.  Even so, they are usually used only to
  294.     force a normal C calling convention for callback functions (when
  295.     you supply intuition, graphics, exec, or whomever with a callback
  296.     function the OS will call you with arguments on the stack).
  297.  
  298.     Specifying neither causes the routine to default to either stack
  299.     args or register args depending on the DCC flags.  Specifying
  300.     __stkargs forces the function to use stack based arguments no
  301.     matter what options are used.  Specifying __regargs forces the
  302.     function to use register based arguments in the same manner.
  303.     Specifying both forces the function to generate two entry points
  304.     (same thing occurs by default when -mr is used).
  305.  
  306.     Please refer to the discussion in REGARGS.DOC for more information
  307.  
  308.     __dynamic
  309.  
  310.     The __dynamic storage qualifier is used to declare routines that
  311.     do not exist at link or load time but will be loaded run-time.
  312.     The overall effect is to generate autoinit code to dynamically
  313.     load an indirect pointer to the declared variable/procedure and
  314.     autoexit code to release your references on said pointer.
  315.  
  316.     DICE transparently declares the variables/procedures as pointers
  317.     and transparently indirects whenever they are used in code.  The
  318.     __dynamic feature is INCREDIBLY POWERFUL, allowing a program to
  319.     interface to third-party object modules at run-time.  Generally,
  320.     this type of interface is more desirable than a shared-library
  321.     when the module in question are huge -- do major things, as well
  322.     as allowing third-party replacement of modules without effecting
  323.     program operation or requiring a relinking of the program.
  324.  
  325.     Please refer to DYNAMIC.DOC for a more involved explanation.
  326.  
  327.     __D0-__D7
  328.     __A0-__A7
  329.  
  330.     These qualifiers may be used to specify explicit registers that
  331.     procedure arguments are to be placed in.  This feature is meant
  332.     for shared libraries and other related things that call procedures
  333.     via specific registers.  Below is an example of a prototype and
  334.     a procedure that uses this feature:
  335.  
  336.     int fubar(__D0 int, __A2 char *);
  337.  
  338.     int
  339.     fubar(n, ptr)
  340.     __D0 int n;
  341.     __A2 char *ptr;
  342.     {
  343.         ...
  344.         return(0);
  345.     }
  346.  
  347.     You can use register storage qualifiers in both old style and new
  348.     style (ANSI) procedure declarations.  To properly reference the
  349.     procedure from another module the other module should contain a
  350.     properly qualified prototype for the procedure.
  351.  
  352.     It is possible to pass arguments in any register except __A7.
  353.     However, when passing an argument in __A4 the procedure in question
  354.     must either use the large-data model or the __geta4 storage
  355.     qualifier to function properly since A4 normally contains the
  356.     data base for the small data model
  357.  
  358.     --------------------------------------------------------------------
  359.                DYNAMIC STACKS (-gs option)
  360.  
  361.     DICE now has a new option, -gs, which generates stack checking code for
  362.     every subroutine.  But, unlike SAS/C or MANX, DICE is able to allocate
  363.     new stack chunks when the current stack runs out.  Essentially this
  364.     means that you can compile and run programs which expect a lot of stack
  365.     without having to remember to give a larger STACK command in your
  366.     CLI.  Since DICE allocates and deallocates stack chunks according to
  367.     program usage, an efficient use of the amiga's memory is made.
  368.  
  369.     There are two global variables associated with this option.  You, the
  370.     programmer, may override either or both of them by declaring them
  371.     yourself.  The variables are:
  372.  
  373.     long _stack_fudge = 4096;
  374.     long _stack_chunk = 32768;
  375.  
  376.     The defaults are shown above.  You can modify these variables either
  377.     by declaring them globally or changing them on the fly (usually from
  378.     main()).
  379.  
  380.     _stack_fudge specifies the minimum amount of stack before DICE creates
  381.     a new stack.  This should be AT LEAST 2048 BYTES!  This parameter MUST
  382.     be able to handle the worst case stack usage for any given subroutine.
  383.  
  384.     The second parameter specifies the chunk size for any new stacks
  385.     created.  A new stack is created whenever the current available
  386.     stack goes below _stack_fudge, but only applies to the next level
  387.     of subroutine... the current subroutine (that detected the low stack
  388.     condition) must be able to run in the old stack.  Stacks are freed
  389.     as they become unused.
  390.  
  391.     If for any reason DICE is unable to allocate a new stack, it will
  392.     call the stack_abort() routine.  If you do not define such a routine,
  393.     the one from the library will be used (which abort()s the program).
  394.  
  395.     If you DO define a stack_abort() routine, then you must take one
  396.     of two actions:
  397.  
  398.     (1) abort() or exit() the program
  399.  
  400.     (2) return (causes DICE to retry allocating the stack)
  401.  
  402.     If DICE is unable to reallocate the stack after (2), it will call
  403.     stack_abort() again.
  404.  
  405.     --------------------------------------------------------------------
  406.                UNIX COMMON VARIABLES (-mu option)
  407.  
  408.     DICE supports UNIX common variables.  Many UNIX programs declare
  409.     non-extern'd variables in header files (e.g. int a; instead of extern
  410.     int a;).  This causes a particular global variable to be declared
  411.     multiple times resulting in 'duplicate declaration' errors when linked
  412.     on an Amiga.  Through the -mu option DICE will allow such multiple
  413.     declarations however I strongly advise that you NOT use the capability
  414.     unless you are porting UNIX specific code.
  415.  
  416.